package ldh.im.dto.codec.binery;

import io.netty.buffer.ByteBuf;
import ldh.im.dto.business.LoginReq;
import ldh.im.dto.business.LoginTokenReq;

public class LoginTokenCodec extends AckToCodec<LoginTokenReq> {

    @Override
    public void encode(LoginTokenReq loginReq, ByteBuf byteBuf) {
        super.encode(loginReq, byteBuf);
        byteBuf.writeLong(loginReq.getUserId());
        writeString(byteBuf, loginReq.getToken());
    }

    @Override
    public void decode(LoginTokenReq loginReq, ByteBuf byteBuf) {
        super.decode(loginReq, byteBuf);
        loginReq.setUserId(byteBuf.readLong());
        loginReq.setToken(readString(byteBuf));
    }

    @Override
    public LoginTokenReq create() {
        return new LoginTokenReq();
    }

    @Override
    public int getAuthCode() {
        return "login".hashCode();
    }
}
